/*
 * dbm_lsdb_manager.h
 *
 *  Created on: 2012-12-11
 *      Author: macro
 */

#ifndef DBM_LSDB_MANAGER_H_
#define DBM_LSDB_MANAGER_H_
#define NOTFOUND 1
#define FOUND 0

#include "cmn/common.h"
#include "lsdb/lsdb.h"

struct link_state_pkt{
	u_int32_t rt_id;
	u_int32_t if_id;
	u_int32_t n_rt_id;
	u_int32_t n_if_id;

	u_int32_t metric;
	u_int32_t state;
	u_int32_t seq;
};


struct ospf_area{
	struct ospf_area* next;
	u_int32_t area_id;
	struct cr_lsdb_link_state* lsList;
};

struct dbmanager
{
	struct dbmanager *next;
	u_int32_t r_id;  //local router id
	id_t lsdb;   //local lsdb
	id_t lidb;  //local lidb
	struct ospf_area* areas;
};

extern struct dbmanager* dbList;
int dbm_manager_init();//step.1
struct dbmanager* create_dbm_manager(u_int32_t area);
int find_dbm_manager(u_int32_t area);
struct dbmanger* get_dbm_manager(u_int32_t area);

struct ospf_area*  dbm_area_init();
struct ospf_area* create_dbm_area(u_int32_t area);



int add_link_state_to_area(struct cr_lsdb_link_state* lsa,u_int32_t az_id);//step.2
int update_link_state_to_area(struct cr_lsdb_link_state* lsa,u_int32_t az_id); //step.3
extern int find_link_state_to_area(struct link_state_key* key,struct cr_lsdb_link_state* lsa,u_int32_t area_id);
//int find_link_state(struct link_state_key key,struct cr_lsdb_link_state* lsa,u_int32_t az_id,struct dbm_autonomous_zone* head);
//int find_link_state_lsdb(struct link_state_key* key,struct cr_lsdb_link_state* lsa,u_int32_t az_id,struct dbm_autonomous_zone* head);
int show_area_lsdb(u_int32_t z_id); //print the area i's lsdb
int show_area_info(u_int32_t z_id); //print the info of area
//extern int show_linkstate(struct cr_lsdb_link_state* lsa);
//extern int find_link_state_in_area(struct link_state_key*,struct cr_lsdb_link_state* ,u_int32_t);
int dbm_get_lsdb(u_int32_t area,char** data);
void* dbm_create_snapshoot(FILE* fp);
void* send_lsdb_snap_shoot(void* args);
void* dbm_save_snapshoot(void* args);
void* save_lsdb_to_file(void* args);
int show_ls(struct cr_lsdb_link_state* lsa);
extern int show_ls_pkt(struct link_state_pkt*);
#endif /* DBM_LSDB_MANAGER_H_ */
